
interface bannerParams {
    url:string
    data?:object
}


export const request = <T>({url,data}:bannerParams) => {
    return new Promise<T>((resolve,reject) => {
        uni.request({
            url,
            data,
            xhrFields: { withCredentials: true },
            success:(res) =>{
                resolve(res.data as T)
            },
            fail:reject
        })
    })
}


export interface BannerRes {
    code:number
    data:string[]
}
export interface SearchResDetail {
    searchWord:string
    iconUrl:string
}

export interface SearchRes {
    code:number
    data:SearchResDetail[]
}
export interface SearchResSuggest {
    keyword:string
}
export interface SearchSuggest {
    code:number
    result:{
        allMatch:SearchResSuggest[]
    }
}
export interface SearchResResult {
    id:number
    name:string
    artists: {
        id:number
        name:string
        img1v1Url:string
    }[]
}
export interface SearchResult {
    code:number
    result:{
        songs:SearchResResult[]
    }
}


export enum showType {
    PHONE = "PHONE",
    EMAIL = "EMAIL",
    QR = "QR"
}



export const getBannerApi = () => {
    return request<BannerRes>({ url :'https://zyxcl.xyz/music/api/homepage/block/page'})
}
export const getHotlistApi = () => {
    return request({url:'https://zyxcl.xyz/music/api/recommend/resource'})
}
export const getList = (id:number) => {
    return request ({url:`https://zyxcl.xyz/music/api/playlist/detail?id=${id}`})
}
export const getSearch = () => {
    return request<SearchRes>({ url:'https://zyxcl.xyz/music/api/search/hot/detail' })
}
export const getSuggest = (keywords:string) => {
    return request <SearchSuggest>({url:'https://zyxcl.xyz/music/api/search/suggest',
        data:{
            keywords,
            type:'mobile'
        }
    })
}
export const getResult = (keywords:string) => {
    return request <SearchResult>({url:'https://zyxcl.xyz/music/api/search',
        data:{
            keywords
        }
    })
}

interface emailType {
    code:number
    cookie:string
    message:string
  }

export const emailApi = (email:string,password:string) => {
    return request <emailType>({url:'https://zyxcl.xyz/music/api/login',
        data:{
            email,
            password,
            md5_password: 'md5'
        }
    })
}
// interface login {
    
// }
// 手机登录
interface CaptchaVerifyType {
    code:number
    data:boolean
    message?:string
  }
  interface captchaLoginType {
    code:number
    message:string
    msg?:string
    cookie?:string
  }
export const phoneApi = (phone:number,captcha:string) => {
    return request <captchaLoginType>({url:'https://zyxcl.xyz/music/api/login/cellphone',
        data:{
            phone,
            captcha
        }
    })
}
// 验证码接口
interface captchaType {
    code:number
    data:boolean
    }
export const captchaApi = (phone:number) => {
    return request<captchaType> ({url:'https://zyxcl.xyz/music/api/captcha/sent',
        data:{
            phone
        }
    })
}


// 二维码 key 生成接口

interface qrKeyType {
    code:number
    data:{
      code:number
      unikey:string
    }
  }
export const qrKeyApi = ()=>{
    return request<qrKeyType>({url:'https://zyxcl.xyz/music/api/login/qr/key'})
}
// 二维码生成接口
interface qrCreateType {
    code:number
    data:{
      qrimg:string
      qrurl:string
    }
  }
export const qrCreateApi = (key:string)=>{
    return request<qrCreateType>({url:'https://zyxcl.xyz/music/api/login/qr/create',
      data:{
        key,
        qrimg:true
      }
    })
  }




//   /login/qr/check
// 二维码检测
interface qrCheckType {
    code:number
    cookie:string
    message:string
  }
export const qrCheckApi = (key:string)=>{
    return request<qrCheckType>({url:'https://zyxcl.xyz/music/api/login/qr/check',
      data:{
        key
      }
    })
  }